<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="crm.util.ParamUtil"%>
<%@page import="crm.control.BargainControl"%>
<%@page import="crm.control.RecepitControl"%>
<%@page import="crm.control.OfferControl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
               int bargainId = ParamUtil.getInt(request,"id");
               int danwei = ParamUtil.getInt(request,"danwei",0);
               int danwei2 = ParamUtil.getInt(request,"danwei2",0);
               String add_money = ParamUtil.getString(request,"add_money","0");
               if(danwei==1){
            	   add_money = String.valueOf(Float.parseFloat(add_money)*10000);
               }
               String add_money2 = ParamUtil.getString(request,"add_money2","0");
               if(danwei2==1){
            	   add_money2 = String.valueOf(Float.parseFloat(add_money2)*10000);
               }
               //System.out.print(add_money);
               if(add_money.equals(add_money2)){
               if(BargainControl.addReturnedMoney(bargainId,add_money)){
            	   if(BargainControl.isComplete(bargainId)){  //若回款金额与合同金额一致，则将跟单状态变为跟单完成（对应为7）
            		    if(RecepitControl.updateStage(OfferControl.getOfferById(BargainControl.getBargainById(bargainId).getOffer_id()).getRecepit_id(),7)){
            		   %>
                	   <script>
                	   alert("添加回款成功，此跟单已经完成（回款金额与合同金额一致）");
                	   //window.location.href="bargain_read.jsp?id=<%=bargainId%>";
                	   location.href=document.referrer;//后退并且刷新
                	   </script>
                	   <%
            		    } }else{
            	   %>
            	   <script>
            	   alert("添加回款成功");
            	   //window.location.href="bargain_read.jsp?id=<%=bargainId%>";
            	   location.href=document.referrer;//后退并且刷新
            	   </script>
            	   <%
               }}else{
            	   %>
            	   <script>
            	   alert("添加回款失败");
            	   //window.location.href="bargain_read.jsp?id=<%=bargainId%>";
            	     location.href=document.referrer;
            	   </script>
            	   <%
               }}else{
            	   %>
            	   <script>
            	   alert("输入金额不一致");
            	   //window.location.href="bargain_read.jsp?id=<%=bargainId%>";
            	   history.go(-1);
            	   </script>
            	   <%
               }
   
%>
</body>
</html>